/*
 * Database.h
 *
 *  Created on: Dec 21, 2011
 *      Author: andrea
 */

#ifndef DATABASE_H_
#define DATABASE_H_

#include "../Packets/PubPkt.h"
#include <set>
#include "../Common/Consts.h"
#include <sqlite3.h>
#include <boost/unordered_map.hpp>
#include "../Util/Util.h"
#include <iostream>
#include "../Common/Timer.h"


typedef struct {
		boost::unordered_map<key_t, PubPkt*>* keyToPktMap;
		std::set<PubPkt*>* resultSet;
} ParamType;


class Database {

public:

	Database();

	virtual ~Database();

	bool insert(PubPkt *pkt, key_t k);

	bool remove(std::pair<timestamp_t, key_t> key);

	void extract(int type, Constraint* parCostraint, int parNumConstraint, timestamp_t parEntryTimestamp, float window, OccurrenceType occurrence, std::set<PubPkt*> &resultSet);

	boost::unordered_map<int, boost::unordered_map<string, ValType > > getRapresentationMap() { return rapresentationMap; };

	std::set<int> typeSet;
	boost::unordered_map<key_t, PubPkt*> keyToPktMap;


private:

	sqlite3* memorydb;
	boost::unordered_map<int, boost::unordered_map<string, ValType > > rapresentationMap;
	boost::unordered_map<key_t, int> keyTypeMatchingMap;

//	std::set<int> typeSet;
//	boost::unordered_map<key_t, PubPkt*> keyToPktMap;

	Timer *timer;
};

namespace db {


int addToResultSet(void* resultSet, int argc, char **argv, char **column);


}

#endif /* DATABASE_H_ */
